using System;
using System.IO;
using System.Reflection;
using Wantn.Share.DataCry;

namespace Wantn.Share
{
	public sealed class AppInfo
	{
		public struct AsmInfo
		{
			public string Name;

			public string Path;
		}

		public static string GetAppDir(Assembly asmApp)
		{
			string text = Path.GetDirectoryName(asmApp.Location);
			if (!text.EndsWith("\\") || text.EndsWith("/"))
			{
				text += "\\";
			}
			return text;
		}

		public static string GetAppFile(Assembly asmApp)
		{
			return asmApp.Location;
		}

		public static string GetAppToken(Assembly asmApp)
		{
			byte[] publicKeyToken = asmApp.GetName().GetPublicKeyToken();
			return BitConverter.ToString(publicKeyToken).Replace("-", string.Empty);
		}

		public static string GetAppVersion(Assembly asmApp)
		{
			return asmApp.GetName().Version.ToString();
		}

		public static string GetAppHash(Assembly asmApp)
		{
			string result = "";
			FileStream fileStream = null;
			try
			{
				string location = asmApp.Location;
				fileStream = new FileStream(location, FileMode.Open, FileAccess.Read);
				byte[] value = SHA1.Encrypt(fileStream);
				result = BitConverter.ToString(value).Replace("-", "");
				return result;
			}
			catch
			{
				return result;
			}
			finally
			{
				if (fileStream != null)
				{
					fileStream.Close();
					fileStream.Dispose();
				}
			}
		}

		public static AsmInfo[] GetAppRefAsmInfo(Assembly asmApp)
		{
			AssemblyName[] referencedAssemblies = asmApp.GetReferencedAssemblies();
			if (referencedAssemblies != null && referencedAssemblies.Length >= 1)
			{
				AsmInfo[] array = new AsmInfo[referencedAssemblies.Length];
				for (int i = 0; i < array.Length; i++)
				{
					array[i].Name = referencedAssemblies[i].Name;
					array[i].Path = Assembly.Load(referencedAssemblies[i].FullName).Location;
				}
				return array;
			}
			return null;
		}

		public static string GetAppTitle(Assembly asmApp)
		{
			object[] customAttributes = asmApp.GetCustomAttributes(typeof(AssemblyTitleAttribute), inherit: false);
			if (customAttributes.Length > 0)
			{
				AssemblyTitleAttribute assemblyTitleAttribute = (AssemblyTitleAttribute)customAttributes[0];
				if (assemblyTitleAttribute.Title != "")
				{
					return assemblyTitleAttribute.Title;
				}
			}
			return Path.GetFileNameWithoutExtension(asmApp.CodeBase);
		}

		public static string GetAppDescription(Assembly asmApp)
		{
			object[] customAttributes = asmApp.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), inherit: false);
			if (customAttributes.Length == 0)
			{
				return "";
			}
			return ((AssemblyDescriptionAttribute)customAttributes[0]).Description;
		}

		public static string GetAppProduct(Assembly asmApp)
		{
			object[] customAttributes = asmApp.GetCustomAttributes(typeof(AssemblyProductAttribute), inherit: false);
			if (customAttributes.Length == 0)
			{
				return "";
			}
			return ((AssemblyProductAttribute)customAttributes[0]).Product;
		}

		public static string GetAppCopyright(Assembly asmApp)
		{
			object[] customAttributes = asmApp.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), inherit: false);
			if (customAttributes.Length == 0)
			{
				return "";
			}
			return ((AssemblyCopyrightAttribute)customAttributes[0]).Copyright;
		}

		public static string GetAppCompany(Assembly asmApp)
		{
			object[] customAttributes = asmApp.GetCustomAttributes(typeof(AssemblyCompanyAttribute), inherit: false);
			if (customAttributes.Length == 0)
			{
				return "";
			}
			return ((AssemblyCompanyAttribute)customAttributes[0]).Company;
		}

		public AppInfo()
		{

		}
	}
}
